package com.pm.controller.log;

import com.pm.common.Response;
import com.pm.common.annotation.CurrentUser;
import com.pm.common.annotation.MyLog;
import com.pm.common.annotation.UserLoginToken;
import com.pm.common.exception.ExpCodeState;
import com.pm.entity.po.log.LightLog;
import com.pm.entity.po.security.User;
import com.pm.mapper.security.UserMapper;
import com.pm.service.log.LightLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = "一键通过消息")
@UserLoginToken
@RestController
@RequestMapping("/lightLogController")
public class LightLogController {
    @Autowired
    LightLogService lightLogService;
    @Autowired
    UserMapper userMapper;

    @ApiOperation("新增接口")
    @PostMapping("/lightLogAdd")
    @ResponseBody
    @MyLog(value = "新增消息")
    public Response<Integer> lightLogAdd(LightLog lightLog, @CurrentUser User user) {
        Response<Integer> response = null;
        lightLog.setAuditor(user.getUserId());
        Integer result = lightLogService.lightLogAdd(lightLog);
        if (result > 0) {
            response = new Response<>(ExpCodeState.add_data_success, result);
        } else {
            response = new Response<>(ExpCodeState.add_data_failed);
        }
        return response;
    }

    @ApiOperation("查询全部消息")
    @PostMapping("/getLightLogList")
    @ResponseBody
    public Response<List<LightLog>> getLightLogList(LightLog lightLog, @CurrentUser User user) {
        Integer id = user.getUserId();
        Integer taskId = userMapper.getTaskId(id);
        lightLog.setTaskId(taskId);
        List<LightLog> result = lightLogService.getLightLogList(lightLog);
        Response<List<LightLog>> res = new Response<List<LightLog>>(ExpCodeState.query_data_success, result);
        return res;
    }

    @ApiOperation("修改全部消息读状态")
    @PostMapping("/updateReda")
    @ResponseBody
    @MyLog(value = "修改打分审核记录读状态")
    public Response<Integer> updateReda(LightLog lightLog) {
        int res = lightLogService.updateReda(lightLog);
        if (res > 0) {
            return new Response<>(ExpCodeState.update_data_success, res);
        } else {
            return new Response<>(ExpCodeState.update_data_failed);
        }
    }
}
